﻿using System;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    public class SkillEffective_Relive : SkillEffective
    {
        protected override bool attackDead => true;

        protected override ISerializeCustomPOD OnExecute(SkillEffectiveData data, Unit target, SkillEffectiveContext context, int effectiveIndex, out SkillEffectiveResponse startResp)
        {
            startResp = null;
            var rAttacker = context.skill.executer;
            if (data.effectiveConfig.customConfig is SkillEffective_Relive_ConfigData rConfig)
            {
                var rDead = target.GetComponent<DeadComponent>(ETComponentType.DeadComponent);
                if (rDead != null)
                {
                    rDead.Relive();
                    target.DeleteComponent(ETComponentType.DeadComponent);


                    var rCureResp = DamageController.TakeCure(rAttacker, target, rConfig.cureFormula, 1);
                    return rCureResp;
                }
            }

            return null;
        }

#if UNITY_EDITOR
        public override string ToString(SkillCustomConfig config)
        {
            var rConfig = config as SkillEffective_Relive_ConfigData;
            return $"复活,回复公式[{rConfig.cureFormula}]";
        }
#endif
    }
}